/**
 * Represents the code of a physical key.kbd
 *
 * This mostly conforms to the UI Events Specification's [`KeyboardEvent.code`] with a few
 * exceptions:
 * - The keys that the specification calls "MetaLeft" and "MetaRight" are named "SuperLeft" and
 *   "SuperRight" here.
 * - The key that the specification calls "Super" is reported as `Unidentified` here.
 * - The `Unidentified` variant here, can still identifiy a key through it's `NativeKeyCode`.
 *
 * [`KeyboardEvent.code`]: https://w3c.github.io/uievents-code/#code-value-tables
 */
export enum KeyCode {
    /**
     * This variant is used when the key cannot be translated to any
     * other variant.
     *
     * The native scancode is provided (if available) in order
     * to allow the user to specify keybindings for keys which
     * are not defined by this API.
     */
    Unidentified,
    /**
     * ``` on a US keyboard. This is also called a backtick or grave.
     * This is the `半角`/`全角`/`漢字`
     * (hankaku/zenkaku/kanji) key on Japanese keyboards
     */
    Backquote,
    /**
     * Used for both the US `\\` (on the 101-key layout) and also for the key
     * located between the `"` and `Enter` keys on row C of the 102-,
     * 104- and 106-key layouts.
     * Labeled `#` on a UK (102) keyboard.
     */
    Backslash,
    /**
     * `[` on a US keyboard.
     */
    BracketLeft,
    /**
     * `]` on a US keyboard.
     */
    BracketRight,
    /**
     * `,` on a US keyboard.
     */
    Comma,
    /**
     * `0` on a US keyboard.
     */
    Digit0,
    /**
     * `1` on a US keyboard.
     */
    Digit1,
    /**
     * `2` on a US keyboard.
     */
    Digit2,
    /**
     * `3` on a US keyboard.
     */
    Digit3,
    /**
     * `4` on a US keyboard.
     */
    Digit4,
    /**
     * `5` on a US keyboard.
     */
    Digit5,
    /**
     * `6` on a US keyboard.
     */
    Digit6,
    /**
     * `7` on a US keyboard.
     */
    Digit7,
    /**
     * `8` on a US keyboard.
     */
    Digit8,
    /**
     * `9` on a US keyboard.
     */
    Digit9,
    /**
     * `=` on a US keyboard.
     */
    Equal,
    /**
     * Located between the left `Shift` and `Z` keys.
     * Labeled `\\` on a UK keyboard.
     */
    IntlBackslash,
    /**
     * Located between the `/` and right `Shift` keys.
     * Labeled `\\` (ro) on a Japanese keyboard.
     */
    IntlRo,
    /**
     * Located between the `=` and `Backspace` keys.
     * Labeled `¥` (yen) on a Japanese keyboard. `\\` on a
     * Russian keyboard.
     */
    IntlYen,
    /**
     * `a` on a US keyboard.
     * Labeled `q` on an AZERTY (e.g., French) keyboard.
     */
    KeyA,
    /**
     * `b` on a US keyboard.
     */
    KeyB,
    /**
     * `c` on a US keyboard.
     */
    KeyC,
    /**
     * `d` on a US keyboard.
     */
    KeyD,
    /**
     * `e` on a US keyboard.
     */
    KeyE,
    /**
     * `f` on a US keyboard.
     */
    KeyF,
    /**
     * `g` on a US keyboard.
     */
    KeyG,
    /**
     * `h` on a US keyboard.
     */
    KeyH,
    /**
     * `i` on a US keyboard.
     */
    KeyI,
    /**
     * `j` on a US keyboard.
     */
    KeyJ,
    /**
     * `k` on a US keyboard.
     */
    KeyK,
    /**
     * `l` on a US keyboard.
     */
    KeyL,
    /**
     * `m` on a US keyboard.
     */
    KeyM,
    /**
     * `n` on a US keyboard.
     */
    KeyN,
    /**
     * `o` on a US keyboard.
     */
    KeyO,
    /**
     * `p` on a US keyboard.
     */
    KeyP,
    /**
     * `q` on a US keyboard.
     * Labeled `a` on an AZERTY (e.g., French) keyboard.
     */
    KeyQ,
    /**
     * `r` on a US keyboard.
     */
    KeyR,
    /**
     * `s` on a US keyboard.
     */
    KeyS,
    /**
     * `t` on a US keyboard.
     */
    KeyT,
    /**
     * `u` on a US keyboard.
     */
    KeyU,
    /**
     * `v` on a US keyboard.
     */
    KeyV,
    /**
     * `w` on a US keyboard.
     * Labeled `z` on an AZERTY (e.g., French) keyboard.
     */
    KeyW,
    /**
     * `x` on a US keyboard.
     */
    KeyX,
    /**
     * `y` on a US keyboard.
     * Labeled `z` on a QWERTZ (e.g., German) keyboard.
     */
    KeyY,
    /**
     * `z` on a US keyboard.
     * Labeled `w` on an AZERTY (e.g., French) keyboard, and `y` on a
     * QWERTZ (e.g., German) keyboard.
     */
    KeyZ,
    /**
     * `-` on a US keyboard.
     */
    Minus,
    /**
     * `Shift`+`=` on a US keyboard.
     *
     * When used as a menu accelerator this is displayed as `+`, and on macOS
     * and Windows the accelerator can be used without pressing the `Shift` key.
     * On Linux the `Shift` key is still required with a US keyboard layout.
     * `Plus` does not work as a value for keyboard accelerators outside menus on
     * keyboards where `+` requires a modifier key.
     */
    Plus,
    /**
     * `.` on a US keyboard.
     */
    Period,
    /**
     * `'` on a US keyboard.
     */
    Quote,
    /**
     * `;` on a US keyboard.
     */
    Semicolon,
    /**
     * `/` on a US keyboard.
     */
    Slash,
    /**
     * `Alt`, `Option`, or `⌥`.
     */
    AltLeft,
    /**
     * `Alt`, `Option`, or `⌥`.
     * This is labeled `AltGr` on many keyboard layouts.
     */
    AltRight,
    /**
     * `Backspace` or `⌫`.
     * Labeled `Delete` on Apple keyboards.
     */
    Backspace,
    /**
     * `CapsLock` or `⇪`
     */
    CapsLock,
    /**
     * The application context menu key, which is typically found between the right
     * `Super` key and the right `Control` key.
     */
    ContextMenu,
    /**
     * `Control` or `⌃`
     */
    ControlLeft,
    /**
     * `Control` or `⌃`
     */
    ControlRight,
    /**
     * `Enter` or `↵`. Labeled `Return` on Apple keyboards.
     */
    Enter,
    /**
     * The Windows, `⌘`, `Command`, or other OS symbol key.
     */
    SuperLeft,
    /**
     * The Windows, `⌘`, `Command`, or other OS symbol key.
     */
    SuperRight,
    /**
     * `Shift` or `⇧`
     */
    ShiftLeft,
    /**
     * `Shift` or `⇧`
     */
    ShiftRight,
    /**
     * ` ` (space)
     */
    Space,
    /**
     * `Tab` or `⇥`
     */
    Tab,
    /**
     * Japanese: `変` (henkan)
     */
    Convert,
    /**
     * Japanese: `カタカナ`/`ひらがな`/`ローマ字` (katakana/hiragana/romaji)
     */
    KanaMode,
    /**
     * Korean: HangulMode `한/영` (han/yeong)
     *
     * Japanese (Mac keyboard): `か` (kana)
     */
    Lang1,
    /**
     * Korean: Hanja `한` (hanja)
     *
     * Japanese (Mac keyboard): `英` (eisu)
     */
    Lang2,
    /**
     * Japanese (word-processing keyboard): Katakana
     */
    Lang3,
    /**
     * Japanese (word-processing keyboard): Hiragana
     */
    Lang4,
    /**
     * Japanese (word-processing keyboard): Zenkaku/Hankaku
     */
    Lang5,
    /**
     * Japanese: `無変換` (muhenkan)
     */
    NonConvert,
    /**
     * `⌦`. The forward delete key.
     * Note that on Apple keyboards, the key labelled `Delete` on the main part of
     * the keyboard is encoded as [`Backspace`].
     *
     * [`Backspace`]: Self::Backspace
     */
    Delete,
    /**
     * `Page Down`, `End`, or `↘`
     */
    End,
    /**
     * `Help`. Not present on standard PC keyboards.
     */
    Help,
    /**
     * `Home` or `↖`
     */
    Home,
    /**
     * `Insert` or `Ins`. Not present on Apple keyboards.
     */
    Insert,
    /**
     * `Page Down`, `PgDn`, or `⇟`
     */
    PageDown,
    /**
     * `Page Up`, `PgUp`, or `⇞`
     */
    PageUp,
    /**
     * `↓`
     */
    ArrowDown,
    /**
     * `←`
     */
    ArrowLeft,
    /**
     * `→`
     */
    ArrowRight,
    /**
     * `↑`
     */
    ArrowUp,
    /**
     * On the Mac, this is used for the numpad `Clear` key.
     */
    NumLock,
    /**
     * `0 Ins` on a keyboard. `0` on a phone or remote control
     */
    Numpad0,
    /**
     * `1 End` on a keyboard. `1` or `1 QZ` on a phone or remote control
     */
    Numpad1,
    /**
     * `2 ↓` on a keyboard. `2 ABC` on a phone or remote control
     */
    Numpad2,
    /**
     * `3 PgDn` on a keyboard. `3 DEF` on a phone or remote control
     */
    Numpad3,
    /**
     * `4 ←` on a keyboard. `4 GHI` on a phone or remote control
     */
    Numpad4,
    /**
     * `5` on a keyboard. `5 JKL` on a phone or remote control
     */
    Numpad5,
    /**
     * `6 →` on a keyboard. `6 MNO` on a phone or remote control
     */
    Numpad6,
    /**
     * `7 Home` on a keyboard. `7 PQRS` or `7 PRS` on a phone
     * or remote control
     */
    Numpad7,
    /**
     * `8 ↑` on a keyboard. `8 TUV` on a phone or remote control
     */
    Numpad8,
    /**
     * `9 PgUp` on a keyboard. `9 WXYZ` or `9 WXY` on a phone
     * or remote control
     */
    Numpad9,
    /**
     * `+`
     */
    NumpadAdd,
    /**
     * Found on the Microsoft Natural Keyboard.
     */
    NumpadBackspace,
    /**
     * `C` or `A` (All Clear). Also for use with numpads that have a
     * `Clear` key that is separate from the `NumLock` key. On the Mac, the
     * numpad `Clear` key is encoded as [`NumLock`].
     *
     * [`NumLock`]: Self::NumLock
     */
    NumpadClear,
    /**
     * `C` (Clear Entry)
     */
    NumpadClearEntry,
    /**
     * `,` (thousands separator). For locales where the thousands separator
     * is a "." (e.g., Brazil), this key may generate a `.`.
     */
    NumpadComma,
    /**
     * `. Del`. For locales where the decimal separator is "," (e.g.,
     * Brazil), this key may generate a `,`.
     */
    NumpadDecimal,
    /**
     * `/`
     */
    NumpadDivide,
    NumpadEnter,
    /**
     * `=`
     */
    NumpadEqual,
    /**
     * `#` on a phone or remote control device. This key is typically found
     * below the `9` key and to the right of the `0` key.
     */
    NumpadHash,
    /**
     * `M` Add current entry to the value stored in memory.
     */
    NumpadMemoryAdd,
    /**
     * `M` Clear the value stored in memory.
     */
    NumpadMemoryClear,
    /**
     * `M` Replace the current entry with the value stored in memory.
     */
    NumpadMemoryRecall,
    /**
     * `M` Replace the value stored in memory with the current entry.
     */
    NumpadMemoryStore,
    /**
     * `M` Subtract current entry from the value stored in memory.
     */
    NumpadMemorySubtract,
    /**
     * `*` on a keyboard. For use with numpads that provide mathematical
     * operations (`+`, `-` `*` and `/`).
     *
     * Use `NumpadStar` for the `*` key on phones and remote controls.
     */
    NumpadMultiply,
    /**
     * `(` Found on the Microsoft Natural Keyboard.
     */
    NumpadParenLeft,
    /**
     * `)` Found on the Microsoft Natural Keyboard.
     */
    NumpadParenRight,
    /**
     * `*` on a phone or remote control device.
     *
     * This key is typically found below the `7` key and to the left of
     * the `0` key.
     *
     * Use `"NumpadMultiply"` for the `*` key on
     * numeric keypads.
     */
    NumpadStar,
    /**
     * `-`
     */
    NumpadSubtract,
    /**
     * `Esc` or `⎋`
     */
    Escape,
    /**
     * `Fn` This is typically a hardware key that does not generate a separate code.
     */
    Fn,
    /**
     * `FLock` or `FnLock`. Function Lock key. Found on the Microsoft
     * Natural Keyboard.
     */
    FnLock,
    /**
     * `PrtScr SysRq` or `Print Screen`
     */
    PrintScreen,
    /**
     * `Scroll Lock`
     */
    ScrollLock,
    /**
     * `Pause Break`
     */
    Pause,
    /**
     * Some laptops place this key to the left of the `↑` key.
     *
     * This also the "back" button (triangle) on Android.
     */
    BrowserBack,
    BrowserFavorites,
    /**
     * Some laptops place this key to the right of the `↑` key.
     */
    BrowserForward,
    /**
     * The "home" button on Android.
     */
    BrowserHome,
    BrowserRefresh,
    BrowserSearch,
    BrowserStop,
    /**
     * `Eject` or `⏏`. This key is placed in the function section on some Apple
     * keyboards.
     */
    Eject,
    /**
     * Sometimes labelled `My Computer` on the keyboard
     */
    LaunchApp1,
    /**
     * Sometimes labelled `Calculator` on the keyboard
     */
    LaunchApp2,
    LaunchMail,
    MediaPlayPause,
    MediaSelect,
    MediaStop,
    MediaTrackNext,
    MediaTrackPrevious,
    /**
     * This key is placed in the function section on some Apple keyboards, replacing the
     * `Eject` key.
     */
    Power,
    Sleep,
    AudioVolumeDown,
    AudioVolumeMute,
    AudioVolumeUp,
    WakeUp,
    Hyper,
    Turbo,
    Abort,
    Resume,
    Suspend,
    /**
     * Found on Sun’s USB keyboard.
     */
    Again,
    /**
     * Found on Sun’s USB keyboard.
     */
    Copy,
    /**
     * Found on Sun’s USB keyboard.
     */
    Cut,
    /**
     * Found on Sun’s USB keyboard.
     */
    Find,
    /**
     * Found on Sun’s USB keyboard.
     */
    Open,
    /**
     * Found on Sun’s USB keyboard.
     */
    Paste,
    /**
     * Found on Sun’s USB keyboard.
     */
    Props,
    /**
     * Found on Sun’s USB keyboard.
     */
    Select,
    /**
     * Found on Sun’s USB keyboard.
     */
    Undo,
    /**
     * Use for dedicated `ひらがな` key found on some Japanese word processing keyboards.
     */
    Hiragana,
    /**
     * Use for dedicated `カタカナ` key found on some Japanese word processing keyboards.
     */
    Katakana,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F1,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F2,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F3,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F4,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F5,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F6,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F7,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F8,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F9,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F10,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F11,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F12,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F13,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F14,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F15,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F16,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F17,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F18,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F19,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F20,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F21,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F22,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F23,
    /**
     * General-purpose function key.
     * Usually found at the top of the keyboard.
     */
    F24,
    /**
     * General-purpose function key.
     */
    F25,
    /**
     * General-purpose function key.
     */
    F26,
    /**
     * General-purpose function key.
     */
    F27,
    /**
     * General-purpose function key.
     */
    F28,
    /**
     * General-purpose function key.
     */
    F29,
    /**
     * General-purpose function key.
     */
    F30,
    /**
     * General-purpose function key.
     */
    F31,
    /**
     * General-purpose function key.
     */
    F32,
    /**
     * General-purpose function key.
     */
    F33,
    /**
     * General-purpose function key.
     */
    F34,
    /**
     * General-purpose function key.
     */
    F35,
}

/**
 * Uppercase backup of enum [`KeyCode`].
 */
export const KeyCodeUppercase: { [key: string]: KeyCode } = {};

for (const key in KeyCode) {
    if (Object.prototype.hasOwnProperty.call(KeyCode, key)) {
        const value = KeyCode[<keyof typeof KeyCode>key];
        KeyCodeUppercase[key.toUpperCase()] = value;
    }
}
